<?php 
session_start();
if( !$_SESSION['isuserlogin'] ){
	die('<script>alert("您还没有登陆！请先登陆！"); location.href="/user/login"</script>');
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>图片上传</title>
<style>
body{margin:0; padding:0;background:#e6e6e6;}
.form, .list{ margin:10px 16px; }
input[type=submit], input[type=button], button{border:solid #FFFFFF 2px; padding:2px 10px; margin:auto 5px; background:#6DC5B4; color:#FFFFFF; }

</style>
<script type="text/javascript" src="/public/js/multifile_compressed.js"></script>
</head>
<body>
<?php 
if(isset($_POST['act']) && $_POST['act']=='r'){
	$filwj=(isset($_POST['lxs']) && $_POST['lxs']=='jdzt')?"jdzt_pic":"zcbz_pic";
	echo "<div id=loading>图片上传中...</div>";
	$na="";
	for( $i=0; $i<10; $i++){
		if(!empty($_FILES['file_'.$i]['name'])){
			$rnd = mt_rand(10, 99);
			$filename = uniqid().$rnd;
			$savename=$filename.strtolower(strstr($_FILES['file_'.$i]['name'], '.'));
			$s_pic= dirname(__FILE__)."/public/upload/daren/".$savename;
			$ss_pic= rtrim(dirname($_SERVER['PHP_SELF']), '/\\')."/public/upload/daren/".$savename;
			if($_FILES['file_'.$i]['size']<1000000){
				if(move_uploaded_file($_FILES['file_'.$i]['tmp_name'],$s_pic)){
				
					$na .= "|$ss_pic";
				
				echo "<script type='text/javascript'>document.getElementById('loading').style.visibility='hidden';
					window.opener.document.getElementById('add_form_pics').innerHTML += '<img src=\"$ss_pic\" width=\"60\" height=\"60\"/>';
					</script>";
					@unlink($_FILES['file_'.$i]['name']);
				}
			}else{ echo "图片太大"; }  
		}else{
			echo "<script type='text/javascript'>
			window.opener.document.getElementById('add_event_pics').value += '$na' ;
			//alert('".$i."张图片上传成功！');
			window.close();</script>";	
			break;
		}
	}
}else{
?>
<div  class="form">
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method = "post">
	<!-- The file element -- NOTE: it has an ID -->
	<input id="my_file_element" type="file" name="file">
	<input type="submit" value="上传">
	<input type="hidden" name="act" value="r">
	<input type="hidden" name="lxs" value="<?php echo $_GET['lxs'];?>">
</form>
</div>
<div class="list"><h2>文件列表:</h2>
<!-- This is where the output will appear -->
<div id="files_list" style="padding:5px; "></div>
</div>
<script>
	<!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
	var multi_selector = new MultiSelector( document.getElementById( 'files_list' ),5);
	<!-- Pass in the file element -->
	multi_selector.addElement( document.getElementById( 'my_file_element' ) );
</script>
<?php }?>
</body>
</html>